<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start();date_default_timezone_set('PRC'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>物料搜索</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="demo.css" rel="stylesheet" type="text/css" />
    <script src="scripts/boot.js" type="text/javascript"></script>
</head>
<body  style="height: 700px">

<div id="panel1" class="mini-panel" title="查询条件" iconCls="icon-search" style="width:100%;height:100px;" 
  showToolbar="true" showCollapseButton="true" showFooter="true" allowResize="true" collapseOnTitleClick="true">

      
        <div  id='fm1'>
        <div class="fieldset-body">
         <span style="margin-left: 8px"> 关键字:</span> <input type="input" class='mini-textbox' id='key' style="width: "/>
         <span style="margin-left: 20px">  品牌:</span>  <input type="input" class='mini-textbox' id='brand' style="width: "/>
        <br/>
		<span>一级类别</span>
        <input id="type1" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid" 
        onvaluechanged="onType1Changed" url="/goods/getCatAjax?type=1"
        showNullItem="true"/> 
        <span>二级类别</span>
        <input id="type2" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid"  onvaluechanged="onType2Changed" /> 
        <span>三级类别</span>
        <input id="type3" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid" /> 
        <a class="mini-button" onclick="search()" enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a>  <a style="margin-top: 5px" class="mini-button" onclick="htmlClick()" enabled="" id='query-bt' >&nbsp;&nbsp;下载数据包&nbsp;&nbsp;</a>

  
   </div>
   </div>
   </div>
   


        <div id="datagrid1" class="mini-datagrid" style="height:530px;width: 100%;margin-top: 10px;" idField="id"  allowResize="true"    showFilterRow="true"   sizeList="[10000,20000,30000]"
          allowCellEdit="true" allowCellSelect="true" multiSelect="true" allowCellValid="true" oncellvalidation=""  url='/goods/queryItemBygoodssearch'   onvaluechanged="onFilterChanged" >
        <div property="columns">
           <div type="checkcolumn" ></div>  
           <div field="code"  headerAlign="center"  >物料编号
             <input id="code" property="filter" class="mini-textbox" style="width:100%;" 
                      onvaluechanged="onFilterChanged"
                />
           </div>   
           <div field="name"  headerAlign="center"  >物料名称
           
             <input id="name" property="filter" class="mini-textbox" style="width:100%;" 
                      onvaluechanged="onFilterChanged"
                />
           </div>    
           
           <div field="U_TypeOption"  headerAlign="center"  >规格
           <input id="U_TypeOption" property="filter" class="mini-textbox" style="width:100%;" 
                      onvaluechanged="onFilterChanged"
                />
           
            </div>
       </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
    </div>



  <div id=''>
    <br/>
    
    
  </div>
</body>
<script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.setPageSize(10000);
        $('.mini-popupedit').css('width','80px')
        function onFilterChanged(e) {
            var namebox = mini.get("name");
            var U_TypeOptionbox = mini.get("U_TypeOption");   
            var codebox = mini.get("code");  
            var name = namebox.getValue().toLowerCase();
            var U_TypeOption = U_TypeOptionbox.getValue().toLowerCase(); 
 			var code = codebox.getValue().toLowerCase();
            //多条件组合过滤
            grid.filter(function (row) {

                //name
                var r1 = true;
                if (namebox) {
                    r1 = String(row.name).toLowerCase().indexOf(name) != -1;
                }

             
                var r2 = true;
                if (U_TypeOption) {
                    r2 = String(row.U_TypeOption).toLowerCase().indexOf(U_TypeOption) != -1;
                }

                var r3 = true;
                if (code) {
                    r3 = String(row.code).toLowerCase().indexOf(code) != -1;
                }
                

                
             

                return r1 && r2 && r3;
            });
        }


        function clearFilter() {
            var namebox = mini.get("name");
            var agebox = mini.get("U_TypeOption");

            namebox.setValue("");
            agebox.setValue("");
            agebox.setFilterValue("");

            grid.clearFilter();
        }

        
      
        grid.on("drawcell", function (e) {
        var record = e.record,
        column = e.column,
        field = e.field,
        value = e.value;
        });
        var type1 = mini.get("type1");
        var type2 = mini.get("type2");
        var type3 = mini.get("type3");
        function onType1Changed(e) {
            var id = type1.getValue();
             if(parseInt(id)>0){
            type2.setValue("");
            var url = "/goods/getCatAjax?type=2&pcatid="+id;
            type2.setUrl(url);
            type2.select(0);
            onType2Changed();
             }else{
            	 type2.setData(null);
            	 type3.setData(null);
		
                 }
        }
        function onType2Changed(e) {
            var id = type2.getValue();
            type3.setValue("");
            var url = "/goods/getCatAjax?type=3&pcatid="+id;
            type3.setUrl(url);
            type3.select(0);
        }

        function search(){
      	  mini.get('panel1').setExpanded(false);
            var key = mini.get('key').getValue();
			var catid=0;
            var type1 = mini.get('type1').getValue();
            var type2 = mini.get('type2').getValue();
            var type3 = mini.get('type3').getValue();
            var brand = mini.get('brand').getValue();
			if(type3!='')
				catid = type3;
			else if (type2!='')
				catid = type2;
			else
				catid = type1;
			grid.load({'key':key,'catid':catid,'brand':brand});
        }

        var htmlContent = document.getElementById("htmlContent");
        function htmlClick() {
				var list = grid.getSelecteds();
				
				var str  = '';
				for(var i=0;i<list.length;i++){
					str+=list[i].code+',';
					
				}
          
        	mini.open({
        	    url: "/sap/goodsdownload.php",
        	    title: "下载数据包", width: 290, height: 150,
        	    onload: function () {
        	        var iframe = this.getIFrameEl();
        	        var data = { data: str};
        	        iframe.contentWindow.SetData(data);
        	    },
        	    ondestroy: function (action) {

        	        grid.reload();
        	    }
        	});
        }

        function download(){

       	 var model = mini.get("rbl").getValue();
         var type  = mini.get("rbl2").getValue();

        
         $.ajax({
             url: "/goods/download",
             data: { model: model,type:type},
             type: "post",
             dataType:'json',
             success: function (data) {
               window.open(data.path+data.file_name);
             },
             error: function (jqXHR, textStatus, errorThrown) {
                 alert(jqXHR.responseText);
             }
         });
         
            }
    </script>

</html>